<%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ page import="entity.Owner" %>
        <%@ page import="entity.PaymentRecord" %>
            <%@ page import="dao.PaymentRecordDao" %>
                <%@ page import="java.util.List" %>
                    <%@ page import="java.text.SimpleDateFormat" %>
                        <html>

                        <head>
                            <title>缴费记录查询</title>
                            <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
                                rel="stylesheet">
                            <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css"
                                rel="stylesheet">
                            <style>
                                body {
                                    background-color: #f8f9fa;
                                    padding-top: 2rem;
                                }

                                .card {
                                    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
                                    border: none;
                                }

                                .table {
                                    margin-bottom: 0;
                                }

                                .back-link {
                                    text-decoration: none;
                                    color: #6c757d;
                                    display: inline-flex;
                                    align-items: center;
                                    gap: 0.5rem;
                                }

                                .back-link:hover {
                                    color: #495057;
                                }

                                .payment-amount {
                                    color: #198754;
                                    font-weight: 500;
                                }

                                .payment-time {
                                    color: #6c757d;
                                    font-size: 0.9rem;
                                }
                            </style>
                        </head>

                        <body>
                            <% Owner owner=(Owner) session.getAttribute("owner"); if (owner==null) {
                                response.sendRedirect("login.jsp"); return; } PaymentRecordDao recordDao=new
                                PaymentRecordDao(); List<PaymentRecord> records =
                                recordDao.getPaymentRecordsByOwnerId(owner.getId());
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                %>

                                <div class="container">
                                    <div class="row justify-content-center">
                                        <div class="col-md-8">
                                            <a href="index.jsp" class="back-link mb-3 d-inline-block">
                                                <i class="bi bi-arrow-left"></i> 返回首页
                                            </a>

                                            <div class="card">
                                                <div class="card-body">
                                                    <h2 class="card-title text-center mb-4">缴费记录查询</h2>
                                                    <div class="table-responsive">
                                                        <table class="table table-hover">
                                                            <thead class="table-light">
                                                                <tr>
                                                                    <th>费用类型</th>
                                                                    <th>缴费数量</th>
                                                                    <th>缴费金额</th>
                                                                    <th>缴费时间</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <% for (PaymentRecord record : records) { %>
                                                                    <tr>
                                                                        <td><i class="bi bi-tag"></i>
                                                                            <%= record.getFeeTypeName() %>
                                                                        </td>
                                                                        <td>
                                                                            <%= record.getQuantity() %>
                                                                        </td>
                                                                        <td class="payment-amount">¥<%=
                                                                                String.format("%.2f",
                                                                                record.getAmount()) %>
                                                                        </td>
                                                                        <td class="payment-time"><i
                                                                                class="bi bi-clock"></i>
                                                                            <%= sdf.format(record.getPaymentTime()) %>
                                                                        </td>
                                                                    </tr>
                                                                    <% } %>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                    <% if (records.isEmpty()) { %>
                                                        <div class="text-center text-muted mt-4">
                                                            <i class="bi bi-inbox h1 d-block"></i>
                                                            <p>暂无缴费记录</p>
                                                        </div>
                                                        <% } %>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <script
                                    src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
                        </body>

                        </html>